<?php
ptaste();
class JEngNullLogger implements ILogger
{
  function debug(){}
  function info(){}
  function warning(){}
  function error(){}
  function fatal(){}
}

class JEngLogger implements ILogger
{
	const LEVEL_DEBUG=0;
	const LEVEL_INFO=1;
	const LEVEL_WARNING=2;
	const LEVEL_ERROR=3;
	const LEVEL_FATAL=4;

	public $fname=false;
	public $level=5;
	
	public $lvs=array("DEBUG","INFO","WARNING","ERROR","FATAL","UNKNOWN");
	
   function __construct($filename,$level)
   {
		$this->level=$this->levelbyname($level);
		$this->fname=$filename;
   }
   
   function levelbyname($name)
   {
     if (is_numeric($name)) 
		return $name;
     for ($i=0;$i<5;$i++)
	   if ($this->lvs[$i]==$name)
	     return $i;
	 return 5;
   }
	
   function logf($level,$vars)
   {
     if ($level<$this->level)
	   return;
	 if ($level<0 || $level>5) $level=5;
	$fmt=array_shift($vars);
	$log=vsprintf($fmt,$vars);
	$logstr=sprintf("%s:%s:%s\n",date("d.m.Y H:i:s"),$this->lvs[$level],$log);
	$f=fopen($this->fname,"a");
	fputs($f,$logstr);
	fclose($f);
   }
   
   function debug()
   {
	 $args=func_get_args();
     $this->logf(self::LEVEL_DEBUG,$args);
   }
   
   function info()
   {
	 $args=func_get_args();
     $this->logf(self::LEVEL_INFO,$args);
   }
   
   function warning()
   {
	 $args=func_get_args();
     $this->logf(self::LEVEL_WARNING,$args);
   }
   
   function error()
   {
	 $args=func_get_args();
     $this->logf(self::LEVEL_ERROR,$args);
   }
   
   function fatal()
   {
	 $args=func_get_args();
     $this->logf(self::LEVEL_FATAL,$args);
   }
}

?>